<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class CI_Site_setting_entity{
	var $current_dbprefix = "";
	var $site_id = 0;
	var $country_ids ="";
	var $province_ids ="";
	var $language_ids ="";
	var $escort_category_ids ="";
	var $sexual_orientation_ids ="";
	var $main_site_language_id = 0;
	
	function __construct() {
		$ci= & get_instance();
		$this->current_dbprefix = $ci->db->dbprefix;
		$ci->db->set_dbprefix('default_');
	}
	function __destruct() {
		$ci= & get_instance();
		$ci->db->set_dbprefix($this->current_dbprefix);
	}
	
	function setSiteId($input){
		$this->site_id=$input;
	}
	function setCountryIds($input){
		$this->country_ids=$input;
	}
	function setProvinceIds($input){
		$this->province_ids=$input;
	}
	function setLanguageIds($input){
		$this->language_ids=$input;
	}
	function setEscortCategoryIds($input){
		$this->escort_category_ids=$input;
	}
	function setSexualOrientationIds($input){
		$this->sexual_orientation_ids=$input;
	}
	function setMainSiteLanguageId($input){
		$this->main_site_language_id=$input;
	}
	function getSiteId(){
		return $this->site_id;
	}
	function getCountryIds(){
		return $this->country_ids;
	}
	function getProvinceIds(){
		return $this->province_ids;
	}
	function getLanguageIds(){
		return $this->language_ids;
	}
	function getEscortCategoryIds(){
		return $this->escort_category_ids;
	}
	function getSexualOrientationIds(){
		return $this->sexual_orientation_ids;
	}
	function getMainSiteLanguageId(){
		return $this->main_site_language_id;
	}
	
	function init($cmd, $input)
	{
		$ci=& get_instance();
		if($cmd == 'site_id'){
			$result = $ci->db->where('site_id',$input)->get(TBL_SITE_SETTING)->result();
		}else if($cmd == 'main_site_language_id'){
			$result = $ci->db->where('main_site_language_id',$input)->get(TBL_SITE_SETTING)->result();
		}else{
			return false;
		}
		if( !empty($result) ){
			$this->site_id = $result[0]->site_id;
			$this->country_ids = $result[0]->country_ids;
			$this->province_ids = $result[0]->province_ids;
			$this->language_ids = $result[0]->language_ids;
			$this->escort_category_ids = $result[0]->escort_category_ids;
			$this->sexual_orientation_ids = $result[0]->sexual_orientation_ids;
			$this->main_site_language_id = $result[0]->main_site_language_id;
			return $this;
		}
		return false;
	}
	function getSiteSettingList(){
		$ci=& get_instance();
		return $ci->db->get(TBL_SITE_SETTING)->result();
	}
	function save($entity){
		$ci=& get_instance();
		$ci->db->set('site_id',$entity->getSiteId());
		$ci->db->set('country_ids',$entity->getCountryIds());
		$ci->db->set('province_ids',$entity->getProvinceIds());
		$ci->db->set('language_ids',$entity->getLanguageIds());
		$ci->db->set('escort_category_ids',$entity->getEscortCategoryIds());
		$ci->db->set('sexual_orientation_ids',$entity->getSexualOrientationIds());
		$ci->db->set('main_site_language_id',$entity->getMainSiteLanguageId());
		$ci->db->insert(TBL_SITE_SETTING);
		return $ci->db->insert_id();
	}
	function update(){
		$ci=& get_instance();
		$ci->db->set('site_id',$this->getSiteId());
		$ci->db->set('country_ids',$this->getCountryIds());
		$ci->db->set('province_ids',$this->getProvinceIds());
		$ci->db->set('language_ids',$this->getLanguageIds());
		$ci->db->set('escort_category_ids',$this->getEscortCategoryIds());
		$ci->db->set('sexual_orientation_ids',$this->getSexualOrientationIds());
		$ci->db->set('main_site_language_id',$this->getMainSiteLanguageId());
		return $ci->db->where('id', $this->id)->update(TBL_SITE_SETTING);
	}
	function delete($id){
		$ci=& get_instance();
		$ci->db->where('site_id',$id);
		$ci->db->delete(TBL_SITE_SETTING);
	}
}